/**
 * 
 */
package com.shequan.shequan.service.impl;

import com.shequan.common.bean.ResultDataStruct;
import com.shequan.common.bean.ViewTextConstans;
import com.shequan.shequan.bean.pojo.ShequanJoinApprove;
import com.shequan.shequan.dao.ShequanJoinApproveDAO;
import com.shequan.shequan.service.ShequanJoinApproveService;
import com.shequan.user.bean.pojo.UserInfo;
import com.shequan.user.dao.UserInfoDAO;

/**
 * <P>
 * Copyright 2012.
 * </p>
 * <P>
 * All Rights Reserved.
 * </p>
 * @author Administrator
 * @version 1.0, 2012-3-12
 * @see com.shequan.shequan.service.impl.ShequanJoinApproveServiceImpl 
 * @since 1.0
 */
public class ShequanJoinApproveServiceImpl implements ShequanJoinApproveService {
	private ShequanJoinApproveDAO shequanJoinApproveDAO;

	public void setShequanJoinApproveDAO(ShequanJoinApproveDAO shequanJoinApproveDAO) {
		this.shequanJoinApproveDAO = shequanJoinApproveDAO;
	}

	/* (non-Javadoc)
	 * @see com.shequan.shequan.service.ShequanJoinApproveService#addUserJoinApprove(java.lang.String)
	 */
	public ResultDataStruct<String> addUserJoinApprove(String shequanIdString, UserInfo userInfo) {
		String[] shequanIds=shequanIdString.split(",");
		ResultDataStruct<String> rds =new ResultDataStruct<String>();
		if(shequanIds.length>10||shequanIds.length<1){
			rds.setBusiSuccess(false);
			rds.setSuccess(true);
			rds.setMessage(ViewTextConstans.USER_JOIN_SHEQUAN_UNSUCCESS_MSG);
		}else{
			ShequanJoinApprove record;
			int rowNum;
			for(int i=0;i<shequanIds.length;i++){
				record=new ShequanJoinApprove();
				record.setApplyUserId((long)userInfo.getUserId());
				record.setJoinShequanId(Long.parseLong(shequanIds[i]));
				rowNum=shequanJoinApproveDAO.insertSelective(record);
				if(rowNum!=1){
					rds.setBusiSuccess(false);
					rds.setSuccess(true);
					rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
				}
			}
		}
		return rds;
	}
}
